<%@page contentType="text/html" import="java.sql.*"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<jsp:useBean id="event" scope="session" class="com.asaga.tools.Event_DBImpl" />
<jsp:useBean id="userProfile" scope="session" class="com.asaga.tools.SystemClient_DBImpl" />
<jsp:useBean id="location" scope="session" class="com.asaga.tools.Location_DBImpl" />
<jsp:useBean id="fontBean" scope="session" class="com.asaga.tools.FontBean" />
<jsp:setProperty name="fontBean" property="*" />

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%  
String username = (String)session.getAttribute("username");
if(username==null){
    response.sendRedirect("login.jsp?message=Please log in again.");
}
ResultSet comments = event.getComments();
%>
<html>
<%@ include file="header.jsp" %>
<body>
    <div id="container">
        <%@ include file="topNav.jsp" %>
        <%@ include file="leftside.jsp" %>
        <%@ include file="rightside.jsp" %>
        <div id="content">
            <p id="warning">
                <jsp:getProperty name="userProfile" property="errmsg" />
                <jsp:getProperty name="userProfile" property="welcomeMsg" />
            </p>
            <h4 class="heading">
                <jsp:getProperty name="event" property="title" /><br />
            </h4>
            <table class="eventForm">
                <tr><td>
                        Date(s):
                    </td>
                    <td>
                        <jsp:getProperty name="event" property="startDate" /> - 
                        <jsp:getProperty name="event" property="endDate" />
                    </td>
                </tr>
                <tr><td>
                        Time:
                    </td>
                    <td>
                        <jsp:getProperty name="event" property="startTime" /> - 
                        <jsp:getProperty name="event" property="endTime" />
                    </td>
                </tr>
                <tr><td>
                    Location:
                </td><td>
                    <jsp:getProperty name="location" property="title" /><br />
                    <jsp:getProperty name="location" property="city" />, 
                    <jsp:getProperty name="location" property="state" />
                </td>
                <tr><td>Description:
                    </td>
                    <td>
                        <jsp:getProperty name="event" property="description" />
                </td></tr>
            </table>
            <%if(userProfile.checkCalender(event.getId())){%>
           <div id="linkHolder">    
                <a href="AutismSiteMasterController?action=removeFromCalendar" class="snippet">Remove Event From Calendar</a>
            </div>
            <%}               
            else if(userProfile.getId() != event.getCreatorId()){%>
            <div id="linkHolder">    
                <img src="images/calendar_icon.gif">
                <a href="AutismSiteMasterController?action=addToCalendar" class="snippet">Attend Event</a>
            </div>
            <%}
            else{%>
            <div id="linkHolder">    
                <img src="images/calendar_icon.gif">
                <a href="AutismSiteMasterController?action=addToCalendar" class="snippet">My Event</a>
            </div>
            <%}%>
        </div> 

            <div id="content">
                <form method="get" action="AutismSiteMasterController">
                <p id="warning">
                </p>
                <h4 class="sub_heading">
                    Comments<br />
                </h4>
                <%if(userProfile.checkDate((java.sql.Date)event.convertDate(event.getEndDate()))){
                if(comments.next()){
                comments.beforeFirst();%>
                <span id="rating">Current Rating: <jsp:getProperty name="event" property="rating" /> stars</span><br />
                <%while(comments.next()){
                %>
                <div class="eventBlock">
                    <span class="userId"><%=comments.getString("nickName")%></span><span class="rating_heading"> says at <%=comments.getTimestamp("theDate")%></span>
                    <br /><br />
                    <%=comments.getString("message")%>
                </div>
               <%}%>
                <fieldset class="eventForm">
                    <legend> Add Feedback</legend>
                    Rating:  
                    1 star<input type="radio" name="rating" value="1" />
                    2 stars<input type="radio" name="rating" value="2" />
                    3 stars<input type="radio" name="rating" value="3" />
                    4 stars<input type="radio" name="rating" value="4" />
                    5 stars<input type="radio" name="rating" value="5" /><br />
                    <textarea name="comment" rows="4" cols="20"></textarea><br />
                    <input type="submit" value="Add Comment" name="action" />
                </fieldset>

                <%}else{%>
                No one has commented on this event<br /><br />
                <fieldset class="eventForm">
                    <legend> Add Feedback</legend>
                    Rating:  
                    1 star<input type="radio" name="rating" value="1" />
                    2 stars<input type="radio" name="rating" value="2" />
                    3 stars<input type="radio" name="rating" value="3" />
                    4 stars<input type="radio" name="rating" value="4" />
                    5 stars<input type="radio" name="rating" value="5" /><br />
                    <textarea name="comment" rows="4" cols="20"></textarea><br />
                    <input type="submit" value="Add Comment" name="action" />
                </fieldset>
                <%}
                }
                else{%>
                The commenting period has not began.
                <%}%>
        </form>
    </div>
    <!--end content -->
    <%@ include file="footer.jsp" %>
    </div>
</body>
</html>